package com.qf.cx.simplenms.common.utils;

public final class StringUtils {

	private static final char[] HEX_ARRAY = "0123456789ABCDEF".toCharArray();

	public static String bytesToHex(final byte[] bytes) {
		char[] hexChars = new char[bytes.length * 2];
		for (int j = 0; j < bytes.length; j++) {
			int v = bytes[j] & 0xFF;
			hexChars[j * 2] = HEX_ARRAY[v >>> 4];
			hexChars[j * 2 + 1] = HEX_ARRAY[v & 0x0F];
		}
		return new String(hexChars);
	}

	public static String shortsToHex(final short[] shorts, final int len) {
		if (shorts == null || shorts.length <= 0) {
			return null;
		}
		byte[] bytes = new byte[len * 2];

		for (int i = 0; i < len; i++) {
			bytes[i * 2] = (byte) (shorts[i] & 0xff);
			bytes[i * 2 + 1] = (byte) ((shorts[i] >> 8) & 0xff);
		}
		return bytesToHex(bytes);
	}

	private StringUtils() {
	}
}
